# -*- coding: utf-8 -*-
import hashlib              # D�ng t�nh hash Md5
import traceback            # D�ng d? x? l� debug
import sys
import os
import re                   # Thu vi?n regex
import urllib
import urllib2
from lxml import etree
from httplib2 import Http
import commonlib
import simplejson as json

def test1():
    data = urllib.urlopen('http://beta.mana.vn:3334/').read()
    print data
    
def test2():
    params = {'url':'http://www.cherrypy.org/chrome/common/cplogo.jpg', 'prefix':'/test/'}
    req = urllib2.Request('http://beta.mana.vn:3334/downloadImage', urllib.urlencode(params))
    data = urllib2.urlopen(req).read()
    print data

def test3():
    params = {'url':'http://vnexpress.net/124123412', 'prefix':'/test/'}
    req = urllib2.Request('http://beta.mana.vn:3334/downloadImage', urllib.urlencode(params))
    data = urllib2.urlopen(req).read()
    print data

def testDownloadMp3():
    params = {'url':'http://stream42.gonct.info/a5513f655a5f31a9364f6e2ac00d489c/4dd395fe/NhacCuaTui152/Xin Loi Anh Se Ra di - Chau Gia Kiet [NCT 75634413363565077500].mp3', 'prefix':'/testmp3/'}
    req = urllib2.Request('http://192.168.145.234:3334/downloadMp3', urllib.urlencode(params))
    data = urllib2.urlopen(req).read()
    res = json.loads(data)
    print res
    print res[1]
    print res[0]
            
# test1()
# test2()
# test2()
# test3()
#testDownloadMp3()
print commonlib.downloadMp3('http://stream42.gonct.info/57a627ad0c2a4e97b3e8a2eee305f2db/4dd3a410/NhacCuaTui152/Tam Biet - Quang Vinh [NCT 46634413385291015000].mp3', './giang1111.mp3')
